//
//  EmptyNotifyView.m
//  YiKeDe
//
//  Created by GuiDaYou on 16/1/17.
//  Copyright © 2016年 李世飞. All rights reserved.
//

#import "LSF_Util.h"


@implementation LSF_Util

#pragma mark + addSuview的方法
/**
 *  创建view
 *
 *  @param rect  CGRectMake
 *  @param viewA 要添加到view
 *  @param color 创建当前view的颜色
 *
 *  @return return value description
 */
+(UIView *)viewWithRect:(CGRect)rect view:(UIView *)viewA backgroundColor:(UIColor *)color
{
    UIView *view=[[UIView alloc]init];
    view.frame=rect;
    view.backgroundColor=color;
    [viewA addSubview:view];
    return view;
}
/**
 *  创建UIButton
 *
 *  @param photo           图片名
 *  @param Hphoto          图片名
 *  @param rect            rect description
 *  @param title           标题
 *  @param sel             action
 *  @param tag             tag description
 *  @param ViewA           ViewA description
 *  @param textcolor       标题颜色
 *  @param size            标题字体大小
 *  @param backgroundColor button背景颜色
 *
 *  @return return value description
 */
+(UIButton*)buttonPhotoAlignment:(NSString*)photo hilPhoto:(NSString*)Hphoto rect:(CGRect)rect  title:(NSString*)title Tag:(NSInteger)tag View:(UIView*)ViewA textColor:(UIColor*)textcolor Size:(UIFont*)size backgroundColor:(UIColor *)backgroundColor{
    UIButton* button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = rect;
    [button setImage:[UIImage imageNamed:photo] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:Hphoto] forState:UIControlStateHighlighted];
    button.contentMode = UIViewContentModeScaleAspectFit;
    [button setTitle:title forState:UIControlStateNormal];
    button.tag=tag;
    [button setTitleColor:textcolor forState:UIControlStateNormal];
    button.titleLabel.font=size;
    button.backgroundColor=backgroundColor;
    [ViewA addSubview:button];
    return button;
}


/**
 *  创建UILabel
 *
 *  @param rect  CGRectMake
 *  @param viewA 要添加到view
 *  @param color 创建当前view的颜色
 *
 *  @return return value description
 */
+(UILabel*)labelName:(NSString*)text   fontSize:(CGFloat)font  rect:(CGRect)rect View:(UIView*)viewA Alignment:(NSTextAlignment)alignment Color:(UIColor*)color Tag:(NSInteger)tag{
    UILabel*label=[[UILabel alloc]initWithFrame:rect];
    label.text=text;
    label.backgroundColor=[UIColor clearColor];
    label.textAlignment=alignment;
    label.textColor=color;
    label.numberOfLines=0;
    label.lineBreakMode=NSLineBreakByTruncatingTail;
    label.font = [UIFont systemFontOfSize:font];
    label.tag=tag;
    [viewA addSubview:label];
    
    return label;
}

/**
 *  创建UITextField
 *
 *  @param rect           rect description
 *  @param tag            tag description
 *  @param color          color description
 *  @param alignment      alignment description
 *  @param textStr        textStr description
 *  @param placeholderStr placeholderStr description
 *  @param viewA          viewA description
 *
 *  @return return value description
 */
+(UITextField*)addTextFieldView:(CGRect)rect Tag:(NSInteger)tag  textColor:(UIColor*)color Alignment:(NSTextAlignment)alignment Text:(NSString*)textStr  placeholderStr:(NSString *)placeholderStr View:(UIView*)viewA font:(CGFloat)font{
    UITextField*textM=[[UITextField alloc] initWithFrame:rect];
    [textM setBackgroundColor:[UIColor clearColor]];
    [textM setTextColor:color];
    textM.tag=tag;
    [textM setFont:[UIFont systemFontOfSize:16.0f]];
    textM.placeholder =placeholderStr;
    textM.text=textStr;
    textM.autocapitalizationType=UITextAutocapitalizationTypeNone;
    textM.textAlignment = alignment;
    textM.font=[UIFont systemFontOfSize:font];
    [viewA addSubview:textM];
    return textM;
}

/**
 *  自定义搜索框
 *
 *  @param frame           frame description
 *  @param fontSize        fontSize description
 *  @param searchIconStr   searchIconStr description
 *  @param searchIconFrame searchIconFrame description
 *  @param placeholder     placeholder description
 *  @param holderColor     holderColor description
 *  @param delegate        delegate description
 *
 *  @return return value description
 */
+(UITextField *)addCommonSearchTextFieldView:(CGRect)frame fontSize:(CGFloat)fontSize searchIconStr:(NSString *)searchIconStr searchIconFrame:(CGRect)searchIconFrame placeholder:(NSString *)placeholder placeholderColor:(UIColor *)holderColor delegate:(id<UITextFieldDelegate>)delegate
{
    UITextField*textM=[[UITextField alloc] initWithFrame:frame];
    textM.delegate=delegate;
    textM.font=[UIFont systemFontOfSize:fontSize];
    textM.placeholder=placeholder;
    if(holderColor)
    {
        [textM setValue:holderColor forKeyPath:@"_placeholderLabel.textColor"];
    }

    UIImageView *searchIcon=[[UIImageView alloc]initWithFrame:searchIconFrame];
    searchIcon.image=[UIImage imageNamed:searchIconStr];
    searchIcon.contentMode=UIViewContentModeCenter;
    textM.leftView=searchIcon;
    textM.leftViewMode=UITextFieldViewModeAlways;
    textM.borderStyle=UITextBorderStyleRoundedRect;
    //设置外围的显示
    textM.layer.cornerRadius = 6;
    textM.layer.borderColor=[UIColor whiteColor].CGColor;
    textM.layer.borderWidth = 1.0;
    
    return textM;
}

/**
 *  创建UIImageView
 *
 *  @param imageName 图片名
 *  @param rect      rect description
 *  @param viewA     viewA description
 *  @param tag       tag description
 *
 *  @return return value description
 */
+(UIImageView*)addSubviewImage:(NSString*)imageName  rect:(CGRect)rect View:(UIView*)viewA Tag:(NSInteger)tag{
    UIImageView*view=[[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];
    view.frame=rect;
    view.userInteractionEnabled=YES;
    view.tag=tag;
    [viewA addSubview:view];
    return view;
}

/**
 *  创建动画
 *
 *  @param view view description
 *  @param rect rect description
 */
+(void)donghuaView:(UIView*)view  Rect:(CGRect)rect{
    [UIView beginAnimations:@"animationID" context:nil];
    [UIView setAnimationDuration:0.35f];
    [view setFrame:rect];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:view cache:YES];
    [UIView commitAnimations];
}



/**
 *  创建UITableView
 *
 *  @param rect       rect description
 *  @param tag        tag description
 *  @param ViewA      ViewA description
 *  @param delegate   delegate description
 *  @param dataSource dataSource description
 *
 *  @return return value description
 */
+(UITableView *)add_tableview:(CGRect)rect Tag:(NSInteger) tag View:(UIView *)ViewA delegate:(id <UITableViewDelegate>)delegate dataSource:(id <UITableViewDataSource>)dataSource
{
    UITableView * tableview =[[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain];
    tableview.delegate=delegate;
    tableview.dataSource=dataSource;
    tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    tableview.tag=tag;
    tableview.backgroundColor=[UIColor clearColor];
    [ViewA addSubview:tableview];
    return tableview;
}

/**
 *  创建UIScrollView
 *
 *  @param rect  rect description
 *  @param tag   tag description
 *  @param ViewA ViewA description
 *  @param co    co description
 *
 *  @return return value description
 */
+(UIScrollView *)add_scollview:(CGRect)rect Tag:(NSInteger) tag View:(UIView *)ViewA co:(CGSize)co
{
    UIScrollView * scrll=[[UIScrollView alloc] initWithFrame:rect];
    scrll.tag=tag;
    scrll.scrollEnabled=YES;
    scrll.contentSize=co;
    [ViewA addSubview:scrll];
    return scrll;
}

/**
 *  通过UILable创建线条
 *
 *  @param color color description
 *  @param rect  rect description
 *  @param View  View description
 *
 *  @return return value description
 */
+(UILabel *)setXianTiao:(UIColor *)color rect:(CGRect)rect view:(UIView *)View
{
    UILabel * lable = [[UILabel alloc] initWithFrame:rect];
    lable.backgroundColor=color;
    [View addSubview:lable];
    return lable;
}

/**
 *  添加左箭头
 *
 *  @param view 要添加的view
 *
 *  @return return value description
 */
+(UIImageView *)addIndicatorInView:(UIView *)view
{
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenW-32, 6, 32, 32)];
    imageView.image=[UIImage imageNamed:@"indicator"];
    [view addSubview:imageView];
    
    return imageView;
}



#pragma mark - 常用工厂方法
/**
 *  16进制转color
 *
 *  @param hexColor hexColor description
 *
 *  @return return value description
 */
+( UIColor *) getColor:( NSString *)hexColor
{
    
    unsigned int red, green, blue;
    
    NSRange range;
    
    range. length = 2 ;
    
    range. location = 0 ;
    
    [[ NSScanner scannerWithString :[hexColor substringWithRange :range]] scanHexInt :&red];
    
    range. location = 2 ;
    
    [[ NSScanner scannerWithString :[hexColor substringWithRange :range]] scanHexInt :&green];
    
    range. location = 4 ;
    
    [[ NSScanner scannerWithString :[hexColor substringWithRange :range]] scanHexInt :&blue];
    
    return [ UIColor colorWithRed :( float )(red/ 255.0f ) green :( float )(green/ 255.0f ) blue :( float )(blue/ 255.0f ) alpha : 1.0f ];
    
}

/**
 *  动态计算label的高度
 *
 *  @param text     内容
 *  @param fontsize 设置字体大小
 *  @param width    一行宽度
 *
 *  @return 返回高度
 */
+ (CGFloat)getLabHeight:(NSString *)text FontSize:(CGFloat)fontsize Width:(NSInteger)width
{
    NSMutableParagraphStyle *paraStyle=[[NSMutableParagraphStyle alloc]init];
    paraStyle.lineBreakMode=NSLineBreakByCharWrapping;
    NSDictionary *attributs=[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:fontsize],NSFontAttributeName,[paraStyle copy],NSParagraphStyleAttributeName,nil];
    
    CGRect rect =[text boundingRectWithSize:CGSizeMake(width, 999999.0f) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributs context:nil];
    //    [text sizeWithFont:[UIFont systemFontOfSize:size] constrainedToSize:CGSizeMake(width, 999999.0f) lineBreakMode:UILineBreakModeWordWrap];
    CGSize theSize=rect.size;
    return theSize.height;
}
/**
 *  动态计算label的宽度
 *
 *  @param text     text description
 *  @param fontsize fontsize description
 *  @param height   height description
 *
 *  @return return value description
 */
+ (CGFloat)getLabWidth:(NSString *)text FontSize:(CGFloat)fontsize Height:(NSInteger)height
{
    NSMutableParagraphStyle *paraStyle=[[NSMutableParagraphStyle alloc]init];
    paraStyle.lineBreakMode=NSLineBreakByCharWrapping;
    NSDictionary *attributs=[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:fontsize],NSFontAttributeName,[paraStyle copy],NSParagraphStyleAttributeName,nil];
    
    CGRect rect =[text boundingRectWithSize:CGSizeMake(999999.0f,height) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributs context:nil];
    CGSize theSize=rect.size;
    return theSize.width;
}


/**去除所有的空格*/
+(NSString *)trimStringAllBlank:(NSString *)oldString
{
    NSString * newString = [oldString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    newString = [newString stringByReplacingOccurrencesOfString:@" " withString:@""];
    return newString;
}

/**
 *  判断对象是否为空
 *
 *  @param obj obj description
 *
 *  @return return value description
 */
+(BOOL)isEmpty:(id)obj
{
    if(obj == nil)
    {
        return YES;
    }
    else if([obj isKindOfClass:[NSString class]])
    {
        NSString *objStr = (NSString *)obj;
        if ([objStr isEqual:@""] || [[self trimStringAllBlank:objStr] isEqual:@"0"])
        {
            return YES;
        }
        if(objStr.length == 0)
        {
            return YES;
        }
    }
    else if([obj isKindOfClass:[NSNumber class]])
    {
        NSNumber *objNum = (NSNumber *)obj;
        if([objNum intValue] == 0)
        {
            return YES;
        }
    }
    else if([obj isKindOfClass:[NSNull class]])
    {
        return YES;
    }
    else
    {
    }
    return NO;
}

/**
 *  判断密码是否满足要求
 *
 *  @param _text _text description
 *
 *  @return return value description
 */
+(BOOL)validatePassWord:(NSString  *)_text
{
    NSString *Regex = @"\\w{6,20}";
    NSPredicate *Test = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", Regex];
    return [Test evaluateWithObject:_text];
}

#pragma mark - 关于日期的几个方法
/**
 *  比较2个日期的大小
 *
 *  @param firstDate  firstDate description
 *  @param secondDate secondDate description
 *
 *  @return return value description
 */
+(BOOL)JudgeTwoDate:(NSString*)firstDate secondDate:(NSString*)secondDate{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *date1=[dateFormatter dateFromString:firstDate];
    NSDate *date2=[dateFormatter dateFromString:secondDate];
    
    NSComparisonResult result = [date1 compare:date2];
    
    //secondDate比firstDate早(小)
    if(result==1){
        return NO;
    }
    //secondDate比firstDate晚(大)
    else{
        return YES;
    }
}

/**
 *  比较2个时间的大小
 *
 *  @param firstDate  firstDate description
 *  @param secondDate secondDate description
 *
 *  @return return value description
 */
+(BOOL)JudgeTwoTime:(NSString*)firstDate secondDate:(NSString*)secondDate{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"HH:mm"];
    
    NSDate *date1=[dateFormatter dateFromString:firstDate];
    NSDate *date2=[dateFormatter dateFromString:secondDate];
    
    NSComparisonResult result = [date1 compare:date2];
    
    //secondDate比firstDate早(小)
    if(result==1){
        return NO;
    }
    //secondDate比firstDate晚(大)
    else{
        return YES;
    }
}


/**
 *  获取现在日期
 *
 *  @return return value description
 */
+(NSString*)getNowDate{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *date= [dateFormatter stringFromDate:[NSDate date]];
    return date;
}

/**
 *  获取现在时间
 *
 *  @return return value description
 */
+(NSString*)getNowTime{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"HH:mm"];
    NSString *date= [dateFormatter stringFromDate:[NSDate date]];
    return date;
}

/**
 *  获取某个日期的前一天或后一天 tag 1:后一天 0:前一天
 *
 *  @param date date description
 *  @param tag  tag description
 *
 *  @return return value description
 */
+(NSString*)getLastOrNextDate:(NSString*)date tag:(int)tag
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *date11=[dateFormatter dateFromString:date];
    NSDate *needDate;
    if (tag==1) {
        needDate=[NSDate dateWithTimeInterval:+(24*60*60) sinceDate:date11];
    }
    else{
        needDate=[NSDate dateWithTimeInterval:-(24*60*60) sinceDate:date11];
    }
    
    NSString *getDate=[dateFormatter stringFromDate:needDate];
    
    return getDate;
}

/**
 *  获取N分钟之后的时间
 *
 *  @param startDate startDate description
 *  @param N         N description
 *
 *  @return return value description
 */
+(NSString*)getNhoursTime:(NSString*)startDate N:(int)N{
    
    NSArray *array=[startDate componentsSeparatedByString:@":"];
    int Hmin=[array[0] intValue]*60;
    int totalMin=Hmin+[array[1] intValue]+N;
    int HH=totalMin/60;
    int mm=totalMin%60;
    NSString *date=[NSString stringWithFormat:@"%d:%d",HH,mm];
    return date;
    
}






/**
 *  获取某个日期几天之后的日期
 *
 *  @param date  date description
 *  @param index index description
 *
 *  @return return value description
 */
+(NSString*)getNextSomeDay:(NSString*)date index:(int)index{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *date11=[dateFormatter dateFromString:date];
    NSDate *needDate;
    
    needDate=[NSDate dateWithTimeInterval:+(24*60*60)*index sinceDate:date11];
    
    NSString *getDate=[dateFormatter stringFromDate:needDate];
    
    return getDate;
}

/**
 *  获取某个日期是星期几
 *
 *  @param date date description
 *
 *  @return return value description
 */
+(NSString*)getWeekFromDate:(NSDate*)date {
    NSArray * arrWeek=[NSArray arrayWithObjects:@"周日",@"周一",@"周二",@"周三",@"周四",@"周五",@"周六",
                       nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    
    NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    
    comps = [calendar components:unitFlags fromDate:date];
    
    NSInteger week = [comps weekday];
    
    NSString *weekTime=[NSString stringWithFormat:@"%@",[arrWeek objectAtIndex:week-1]];
    
    return weekTime;
    
}

/**
 *  获取某个日期是星期几
 *
 *  @param date date description
 *
 *  @return return value description
 */
+(NSString*)getWeekFromDateStr:(NSString*)date {
    NSArray * arrWeek=[NSArray arrayWithObjects:@"周日",@"周一",@"周二",@"周三",@"周四",@"周五",@"周六",
                       nil];
    NSDate *date11;
    if (!date) {
        date11 = [NSDate date];
    }
    else{
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        date11=[dateFormatter dateFromString:date];
    }
    
    NSLog(@"date===%@",date);
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    
    NSInteger unitFlags =  NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    
    comps = [calendar components:unitFlags fromDate:date11];
    
    NSInteger week = [comps weekday];
    
    NSString *weekTime=[NSString stringWithFormat:@"%@",[arrWeek objectAtIndex:week-1]];
    
    return weekTime;
}

/**
 *  将NSString转换为NSDate
 *
 *  @param date date description
 *
 *  @return return value description
 */
+ (NSString *)stringFromDate:(NSDate *)date{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    //zzz表示时区，zzz可以删除，这样返回的日期字符将不包含时区信息。
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSString *destDateString = [dateFormatter stringFromDate:date];
    
    return destDateString;
    
}

/**
 *  将NSDate转换成NSString
 *
 *  @param dateStr dateStr description
 *
 *  @return return value description
 */
+ (NSDate *)dateFromString:(NSString *)dateStr
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    //zzz表示时区，zzz可以删除，这样返回的日期字符将不包含时区信息。
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *destDate = [dateFormatter dateFromString:dateStr];
    
    return destDate;
    
}


#pragma mark - 图片处理

/**
 *  将图片比例压缩成正方形
 *
 *  @param image   image description
 *  @param newSize newSize description
 *
 *  @return return value description
 */
+ (UIImage *)squareImageFromImage:(UIImage *)image scaledToSize:(CGFloat)newSize {
    CGAffineTransform scaleTransform;
    CGPoint origin;
    
    if (image.size.width > image.size.height) {
        //image原始高度为200，缩放image的高度为400pixels，所以缩放比率为2
        CGFloat scaleRatio = newSize / image.size.height;
        scaleTransform = CGAffineTransformMakeScale(scaleRatio, scaleRatio);
        //设置绘制原始图片的画笔坐标为CGPoint(-100, 0)pixels
        origin = CGPointMake(-(image.size.width - image.size.height) / 2.0f, 0);
    } else {
        CGFloat scaleRatio = newSize / image.size.width;
        scaleTransform = CGAffineTransformMakeScale(scaleRatio, scaleRatio);
        
        origin = CGPointMake(0, -(image.size.height - image.size.width) / 2.0f);
    }
    
    CGSize size = CGSizeMake(newSize, newSize);
    //创建画板为(400x400)pixels
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
        UIGraphicsBeginImageContextWithOptions(size, YES, 0);
    } else {
        UIGraphicsBeginImageContext(size);
    }
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    //将image原始图片(400x200)pixels缩放为(800x400)pixels
    CGContextConcatCTM(context, scaleTransform);
    //origin也会从原始(-100, 0)缩放到(-200, 0)
    [image drawAtPoint:origin];
    
    //获取缩放后剪切的image图片
    image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
}

/**
 *  将图片比例压缩成长方形
 *
 *  @param sourceImage sourceImage description
 *  @param size        size description
 *
 *  @return return value description
 */
+(UIImage *)imageCompressForSize:(UIImage *)sourceImage targetSize:(CGSize)size{
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = size.width;
    CGFloat targetHeight = size.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0, 0.0);
    if(CGSizeEqualToSize(imageSize, size) == NO){
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        if(widthFactor > heightFactor){
            scaleFactor = widthFactor;
        }
        else{
            scaleFactor = heightFactor;
        }
        scaledWidth = width * scaleFactor;
        scaledHeight = height * scaleFactor;
        if(widthFactor > heightFactor){
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }else if(widthFactor < heightFactor){
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    }
    
    UIGraphicsBeginImageContext(size);
    
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width = scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    [sourceImage drawInRect:thumbnailRect];
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    if(newImage == nil){
        NSLog(@"scale image fail");
    }
    UIGraphicsEndImageContext();
    return newImage;
    
}



#pragma mark - 判断字符串是否是纯数字

/**
 *  判断是否为纯数字
 *
 *  @param numStr numStr description
 *
 *  @return return value description
 */
+(BOOL)isPureNumber:(NSString *)numStr
{
    if( ![self isPureInt:numStr] || ![self isPureFloat:numStr])
    {
        return NO;
    }
    return YES;
}

/**
 *  判断是否为整形
 *
 *  @param string string description
 *
 *  @return return value description
 */
+ (BOOL)isPureInt:(NSString*)string
{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}

/**
 *  判断是否为浮点形
 *
 *  @param string string description
 *
 *  @return return value description
 */
+ (BOOL)isPureFloat:(NSString*)string
{
    NSScanner* scan = [NSScanner scannerWithString:string];
    float val;
    return[scan scanFloat:&val] && [scan isAtEnd];
}

@end
